class Solution(object):
    def canFormArray(self, arr, pieces):
        d = {num: index for index, num in enumerate(arr)}
        for p in pieces:
            if p[0] in d:
                last = d[p[0]]
            else:
                return False
            for i in range(1, len(p)):
                if p[i] in d and d[p[i]] == last + 1:
                    last = d[p[i]]
                else:
                    return False
        return True
